from PyQt4.QtGui import QDockWidget, QFontMetrics, QIcon,  QWidget,QVBoxLayout

from PyQt4.QtCore import pyqtSignal, QSize, Qt, QTimer

class DockContents(QWidget):
    _sizehint = None

    def setSizeHint(self, width, height):
        self._sizehint = QSize(width, height)

    def sizeHint(self):
        print('sizeHint:', self._sizehint)
        if self._sizehint is not None:
            if self._sizehint.width > 1 and self._sizehint.height> 1:
                return self._sizehint
        return super(DockContents, self).sizeHint()


class DockWidget(QDockWidget):
    closed = pyqtSignal()
    shown = pyqtSignal()
    def __init__(self, parent, windowTitle):
        super(DockWidget, self).__init__(parent)
        self._showAction = None
        self.setObjectName(str(self.__class__))
        self.setWindowTitle(windowTitle)
        self.contents = DockContents(self)
        self.layout = QVBoxLayout(self.contents)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.setWidget(self.contents)

    def setSize(self,width,height):
        self.contents.setSizeHint(width, height)


    def addWidget(self,widget):
        self.layout.addWidget(widget)

    def closeEvent(self, event):
            """Widget was closed"""
            self.closed.emit()

    def showEvent(self, event):
            """Widget was shown"""
            self.shown.emit()